﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FDeal.PH_NguoiDung;
using FDeal.WUC;
using BUS;
using DAO;

namespace FDeal
{
    public partial class MemberMuaHang_4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string iddeal = Request.QueryString["id"].ToString();

                //Lấy thong tin luu tam trong bang ra
                Label1.Text = DangNhap.current.HOTEN;
                Label2.Text = DangNhap.current.DIENTHOAI;
                Label3.Text = DonHangTam.diachinhan;

                ThanhToanBUS ttbus = new ThanhToanBUS();
                THANHTOAN tt = ttbus.ChiTiet(DonHangTam.idthanhtoan);

                Label4.Text = tt.TENHINHTHUC;

                ChiTietDealBUS ctbus = new ChiTietDealBUS();
                CHITIETDEAL ct = ctbus.ChiTiet(DonHangTam.iddeal);

                Label5.Text = ct.TIEUDE;
                Label6.Text = DonHangTam.soluong.ToString();
                Label7.Text = ct.GIACONLAI.ToString();
                Label8.Text = DonHangTam.tongtien.ToString();

                ImageButton1.PostBackUrl += iddeal;
                Them();
            }
        }       

        private static void Them()
        {
            DonHangBUS dhbus = new DonHangBUS();
            List<DONHANG> temp = dhbus.DonHangMoiNhat();
            int a = int.Parse(temp[0].IDDONHANG.Substring(2)) + 1;
            string ma = "DH" + a.ToString("000000");
            DonHangTam.iddonhang = ma;

            DONHANG them = new DONHANG();
            them.IDDONHANG = ma;
            them.IDTHANHTOAN = DonHangTam.idthanhtoan;
            them.DIACHINHAN = DonHangTam.diachinhan;
            them.TINHTHANH = DonHangTam.tinhthanh;
            them.QUANHUYEN = DonHangTam.quan;
            them.IDDEAL = DonHangTam.iddeal;
            them.SOLUONG = DonHangTam.soluong;
            them.TONGGIA = DonHangTam.tongtien;
            them.HINHTHUCNHANHANG = "TT000000";
            them.TAIKHOAN = DonHangTam.taikhoan;
            them.TRANGTHAI = "Đang Giao Hàng";

            dhbus.Them(them);
        }
    }
}